<?php
namespace Admin\Controller;
use Think\Controller;
use Admin\Common\AdminController;
class CateController extends AdminController {
    function showlist(){
        //表单的展示
        $cate_info = D('Cate')->select();
        $this->assign('cate_info',$cate_info);
        $this->display();
    }
    function add(){
        //表单的收集
        if(IS_POST){
            $data = I('post.');
            if($id = D('Cate')->add($data)){
                $this->success('分类添加成功',U('showlist'),3);
            }else{
                $this->error('分类添加失败',U('add',array('cate_id'=>$id)),3);
            }
        }
        $this->display();
    }
    function upd(){
        if(IS_POST){
            //表单信息的收集
            $data = I('post.');
            if(D('Cate')->save($data)){
                $this->success('修改成功',U('Cate/showlist'),2);
            }else{
                $this->error('修改失败',U('Cate/upd',array('cate_id'=>$data['cate_id'])),3);
            }
        }else{
            //表单的显示
            $cate_id = I('get.cate_id');
            $cate_info = D('Cate')->where(array('cate_id'=>$cate_id))->select();
            $this->assign('cate_info',$cate_info);
            $this->display();
        }
    }
    function delete(){
        //接受传递的参数
        $cate_id = I('post.cate_id');
        if(D('Cate')->delete($cate_id)){
            echo json_encode(array('status'=>1));
        }else{
            echo json_encode(array('status'=>0));
        }
    }
}